/**
 * @author Cator Vee  hi@catorv.com
 */
import { Component } from 'react'
import PropTypes from 'prop-types'
import wechat from '../lib/wechat'

export default class WechatShareOptions extends Component {
  constructor (props) {
    super(props)
    this.scene = props.scene || 'default'
  }

  componentDidUpdate () {
    let options = {...this.props}
    if (options.scene) {
      delete options.scene
    }
    wechat.updateShareOptions({[this.scene]: options})
  }

  componentWillUnmount () {
    wechat.updateShareOptions({[this.scene]: null})
  }

  render () {
    return null
  }
}

WechatShareOptions.propTypes = {
  scene: PropTypes.oneOf(['default', 'friend', 'timeline', 'qq', 'weibo', 'qzone']),
  title: PropTypes.string,
  desc: PropTypes.string,
  link: PropTypes.string,
  imgUrl: PropTypes.string,
  onSuccess: PropTypes.func,
  onFail: PropTypes.func,
  onCancel: PropTypes.func,
  onComplete: PropTypes.func
}
